<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Exp-Inlet-Gateway</title>
	<link rel="stylesheet" href="/static/style/main.css">
	<link rel="stylesheet" href="/static/framework/bootstrap.min.css">
	<script src="/static/framework/jquery.min.js"></script>
	<script src="/static/framework/bootstrap.bundle.min.js"></script>
</head>
<#--  以下JS文件必须在JQuery加载完才能加载  -->
<script src="/static/script/main.js"></script>
<#--  以下JS文件必须在JQuery加载完才能加载  -->
<body class="container" style="min-width: 1310px;">
<nav class="navbar navbar-expand-lg navbar-light container-fluid">
	<div class="container-fluid  bg-light">
		<a href="/static/app/list" class="navbar-brand text-start"
		   style="font-family: 微软雅黑,serif; color: #3030ff; font-size: 24px;">Exp-Inlet</a>
		<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>
		<div class="collapse navbar-collapse" aria-label="breadcrumb" style="line-height: 1px; text-align: center;align-items: center;">
			<ol class="breadcrumb" style="margin-bottom: 0;">
<#--				<li class="breadcrumb-item"><a href="#">Exp-Inlet</a></li>-->
				<li class="breadcrumb-item active" aria-current="page"><a href="/static/app/list">应用列表</a></li>
				<li class="breadcrumb-item active" aria-current="page"><a href="#">应用详情</a></li>
				<li class="breadcrumb-item active" aria-current="page"><a href="/static/SysInfos.html">运行状态</a></li>
			</ol>
		</div>
		<form class="d-flex">
			<input class="form-control w-75 me-2" style="height: 32px;" type="search" placeholder="Search" aria-label="Search">
			<button class="btn btn-outline-success" style="width: 80px" type="submit" onclick="$.loginOut()"><a class="" href="javascript:;"><span>退出</span></a></button>
		</form>
	</div>
</nav>
<div class="show-tips-model" style="display: none;">
    <div class="tips-body">
        <div class="tips-info">
           	 应用启动中...
        </div>
        <h1 class="tips-progress"></h1>
    </div>
</div>
<div class="container">
	<div class="panel panel-default mt-2 mb-2">
		<div class="panel-heading">
			<h3 class="panel-title">
				<div class="row">
					<div class="col-md-9" style="line-height: 30px;">
						<span class="fs-3"> ${context.app.appName} </span>
						<#if context.app.scope==2><span class="scope-formal" style="font-size: 12px;"> 正式版</span>
						<#elseif context.app.scope==1><span class="scope-pre" style="font-size: 12px;">预览版</span>
						<#else><span class="scope-test" style="font-size: 12px;">测试版</span></#if>
					</div>
					<div class="col-md-1">
						<#if context.app.online == true>
							<button type="button" class="btn btn-warning right" onclick="unDeploy('${context.app.appName}')" >暂停</button>
						<#else>
							<button type="button" class="btn btn-success right" onclick="deploy('${context.app.appName}')" >启动</button>
						</#if>
					</div>
					<div class="col-md-1">
						<a href="/static/app/update/${context.app.appName}">
							<button type="button" class="btn btn-primary right" >修改</button>
						</a>
					</div>
					<div class="col-md-1">
						<button type="button" class="btn btn-danger right" onclick="del('${context.app.appName}')">删除</button>
					</div>
				</div>
			</h3>
		</div>
		<div class="panel-body">${context.app.describe}</div>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">应用服务集</span>
		</div>
		<#if context.app.serverOptions.createHttp== true>
			<a class="list-group-item">HTTP服务 : <span class="text-primary">已开启</span> | 端口号 : <span class="text-primary">${context.app.serverOptions.httpPort?c}</span> </a>
		</#if>
		 <#if context.app.serverOptions.createHttps== true>
			<a class="list-group-item">HTTPS服务 : <span class="text-primary">已开启</span> | 端口号 : <span class="text-primary">${context.app.serverOptions.httpsPort?c}</span> | 证书类型 :<span class="text-primary">${context.app.serverOptions.certOptions.certType}</span></a>
		</#if>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">跨域配置</span>
		</div>
		<#if context.app.corsOptions?exists> 
			<a class="list-group-item">allowedOrigin : <span class="text-primary"> ${context.app.corsOptions.allowedOrigin! }</span></a>
			<a class="list-group-item">allowCredentials : <span class="text-primary"> ${context.app.corsOptions.allowCredentials?c}</span></a>
			<a class="list-group-item">maxAgeSeconds : <span class="text-primary"> ${context.app.corsOptions.maxAgeSeconds?c}</span></a>
			<a class="list-group-item">allowedHeaders :
				<span class="text-primary">
					<#if context.app.corsOptions.allowedHeaders?exists> 
						<#list context.app.corsOptions.allowedHeaders as header>${header}<#sep>, </#sep></#list> 
					</#if>
				</span>
			</a> 
			<a class="list-group-item">exposedHeaders :
				<span class="text-primary">
					<#if context.app.corsOptions.exposedHeaders?exists> 
						<#list context.app.corsOptions.exposedHeaders as header>${header}<#sep>, </#sep></#list> 
					</#if>
				</span>
			</a> 
			<a class="list-group-item">allowedMethods : 
				<span class="text-primary">
					<#if context.app.corsOptions.allowedMethods?exists> 
						<#list context.app.corsOptions.allowedMethods as method>${method}<#sep>, </#sep></#list> 
					</#if>
				</span>
			</a> 
		<#else> 
			<a class="list-group-item"><span>尚未开启跨域处理</span></a>
		</#if>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">找不到资源(404) 返回</span>
		</div>
		<a class="list-group-item"><span>Content-Type : </span><span class="text-primary">${context.app.notFoundContentType!"text/html"}</span></a>
		<a class="list-group-item"><span>内容 : </span><span class="text-primary">${context.app.notFoundResult! }</span></a>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">在黑名单列表中返回</span>
		</div>
		<a class="list-group-item"><span>状态码 : </span><span class="text-primary"><#if context.app.blacklistIpCode?exists>${context.app.blacklistIpCode?c}</#if></span></a>
		<a class="list-group-item"><span>Content-Type : </span><span class="text-primary">${context.app.blacklistIpContentType!}</span></a>
		<a class="list-group-item"><span>内容 : </span><span class="text-primary">${context.app.blacklistIpResult! }</span></a>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">服务器参数配置</span>
		</div>
		<a class="list-group-item">请求主体(Content-Length)最大长度限制: <span class="text-primary">${context.app.contentLength?c}</span></a>
		<a class="list-group-item">会话超时时间 : <span class="text-primary">${context.app.sessionTimeOut?c} ms</span></a>
		<a class="list-group-item">会话的cookie名称 : <span class="text-primary">${context.app.sessionCookieName}</span></a>
		<a class="list-group-item">HTTP对象解码器缓冲区大小 : <span class="text-primary">${context.app.decoderInitialBufferSize?c}</span></a>
		<a class="list-group-item">API与后台服务器是否使用keepAlive : <span class="text-primary">${context.app.keepAlive?c}</span>
		</a> <a class="list-group-item">API与后台服务器交互线程数 : <span class="text-primary">${context.app.maxPoolSize?c}</span></a>
		<a class="list-group-item">请求后端URL参数值最大总长度: <span class="text-primary">${context.app.maxInitialLineLength?c}</span></a>
		<a class="list-group-item">请求后端Header参数值最大总长度: <span class="text-primary">${context.app.maxHeaderSize?c}</span></a>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">业务处理HttpClient拓展配置</span>
		</div>
		<a class="list-group-item">拓展配置 : <span class="text-primary">${context.app.webClientCustom!}</span></a>
	</div>
	<div class="list-group mb-2">
		<div class="console-panel-header">
			<span class="console-panel-header-line"></span>
			<span class="fw-bold">应用服务拓展配置</span>
		</div>
		<a class="list-group-item">拓展配置 : <span class="text-primary">${context.app.serverOptions.custom!}</span></a>
	</div>
</div>
<script>
function deploy(id) {
	$(".tips-info").text("应用启动中...");
	$(".show-tips-model").fadeIn(300);
	$.ajax({
		type : "post",
		url : '/static/app/online/' + id,
		dataType : "json",
		success : function(result) {
			$(".show-tips-model").hide();
			if (result.code !== 200) {
				 $.showNotice("ERROR", "启动应用失败!");
				console.log("启动应用失败", result);
				return;
			}

			if(result.code === 1111){
				 $.showNotice("ERROR", "启动应用失败,该端口号已被别的程序占用!");
				console.log("启动应用失败", result);
				return;
			}

			const res = result.data;
			if (res === 0) {
				 $.showNotice("ERROR", "启动应用失败了!");
				console.log("启动应用失败了", result);
				return;
			}

			if (window.confirm(('启动应用成功,是否启动该应用所有API'))) {
				startAPI(id);
			}else {
				location.reload();
			}
		},
		error : function(msg) {
			$(".show-tips-model").hide();
			 $.showNotice("ERROR", "启动应用失败!");
			console.error("启动应用失败", msg);
		}
	});
}
//启动所有API
function startAPI(id){
	$(".tips-info").text("所有API启动中...");
	$(".show-tips-model").fadeIn(300);
	$.ajax({
		type : "post",
		url : '/static/api/start/all/' + id,
		dataType : "json",
		success : function(result) {
			$(".show-tips-model").hide();
			if (result.code === 200) {
				var res = result.data;
				 $.showNotice("SUCCESS", res);
				location.reload();
			}
			 $.showNotice("ERROR", "启动所有API失败!");
			console.error("启动应用失败", result);
			location.reload();

		},
		error : function(msg) {
			$(".show-tips-model").hide();
			 $.showNotice("ERROR", "启动所有API失败!");
			console.error("启动应用失败", msg);
		}
	});
}


function unDeploy(id) {
	if (window.confirm(('暂停可能影响你的业务,确定暂停吗?'))) {
		$.ajax({
			type : "post",
			url : '/static/app/offline/' + id,
			dataType : "json",
			success : function(result) {
				if (result.code !== 200) {
					 $.showNotice("ERROR", "暂停应用失败!");
					console.log(result.data);
					return;
				}
				var res = result.data;
				if (res == 0) {
					 $.showNotice("ERROR", "暂停应用失败了!");
					console.log(result)
				} else {
					location.reload();
				}
			},
			error : function(msg) {
				 $.showNotice("ERROR", "暂停应用失败了!");
				console.error(msg)
			}
		});
	}
}

function del(id) {
	if (${context.app.online?c}){
		alert('请先将程序暂停后再执行删除操作');
		return;
	}
	if (window.confirm('确定删除' + id + "吗?")) {
		$.ajax({
			type : "post",
			url : '/static/app/del/' + id,
			async : true,
			dataType : "json",
			success : function(result) {
				if (result.code !== 200) {
					 $.showNotice("ERROR", "删除失败!");
					console.log(result);
					return;
				}
				var res = result.data;
				if (res === 0) {
					 $.showNotice("ERROR", "删除失败!");
					console.log(result.data);
				} else {
					 $.showNotice("ERROR", "删除成功!");
					window.location.href = "/static/app/list";
				}
			},
			error : function(msg) {
				 $.showNotice("ERROR", "删除失败!");
				console.error(msg);
			}
		});
	}
}
</script>
</body>

</html>